package com.gxa.learning.pc.config;

import com.gxa.learning.pc.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器的注册器设定拦截哪些方法
 *
 * @author YXQ
 * @date 2021/12/14 21:12
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加注册器,设置哪些路径会被拦截
        // 这样设置了只拦截哪些内容，缩小了拦截范围，一些不需要拦截的资源就不会被拦截
        registry.addInterceptor(getTokenInterceptor())
                .addPathPatterns("/trainPlan/**")
                .addPathPatterns("/home/**")
                .addPathPatterns("/remark/**")
                .addPathPatterns("/levelMgr/**")
                .addPathPatterns("/exap/**")
                .addPathPatterns("/role/**")
                .addPathPatterns("/company/**")
                .addPathPatterns("/department/**")
                .addPathPatterns("/user/**")
                .addPathPatterns("/type/**")
                .addPathPatterns("/msg/**")
                .addPathPatterns("/project/**")
                .addPathPatterns("/course/**")
                .addPathPatterns("/certificate/**")
                .addPathPatterns("/QuestionBank/**")
                .addPathPatterns("/question/**")
                .addPathPatterns("/queTemplate/**")
                .addPathPatterns("/student/**")
                .addPathPatterns("/template/**")
                .addPathPatterns("/feedback/**")

        ;
    }

    @Bean
    public TokenInterceptor getTokenInterceptor() {
        return new TokenInterceptor();
    }
}
